package cc.rengu.igas.route.core.realize.credit.impl.hvps;


import cc.rengu.igas.route.common.enums.SmartRouteRspEnums;
import cc.rengu.igas.route.core.realize.credit.DstChannelCreditService;
import cc.rengu.igas.route.facade.request.IntelligenceCreditRequest;
import cc.rengu.igas.route.facade.request.IntelligenceResultQueryRequest;
import cc.rengu.igas.route.facade.response.IntelligenceCreditResponse;
import cc.rengu.igas.route.facade.response.IntelligenceResultQueryResponse;
import cc.rengu.igas.share.common.constant.ShareParamConstant;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.utility.util.StringUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * TODO 大额贷记实现 由项目组实现ESB模块调用
 *
 * @author xionglz
 * @version 1.0
 * @date 2020-04-28
 */
public class HvpsCreditServiceImpl implements DstChannelCreditService {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getSimpleName());

    @Override
    public IntelligenceCreditResponse credit(IntelligenceCreditRequest intelligenceCreditRequest) throws Exception {
        IntelligenceCreditResponse intelligenceCreditResponse = new IntelligenceCreditResponse();
        intelligenceCreditResponse.setHeader(intelligenceCreditRequest.getHeader());
        intelligenceCreditResponse.setDstChannelTxnNum("00010000614201");
        intelligenceCreditResponse.setDstChannelId("HVPS");
        //TODO  删除调用ESB模块，后续由项目组实现该模块调用

        return intelligenceCreditResponse;
    }

    @Override
    public IntelligenceResultQueryResponse query(IntelligenceResultQueryRequest resultQueryRequest) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        IntelligenceResultQueryResponse intelligenceResultQueryResponse = new IntelligenceResultQueryResponse();
        intelligenceResultQueryResponse.setHeader(resultQueryRequest.getHeader());

        //TODO  删除调用ESB模块，后续由项目组实现该模块调用

        return intelligenceResultQueryResponse;
    }

    @Override
    public String getReconKey(IntelligenceCreditRequest intelligencecreditRequest) throws Exception {
        //无卡快捷间连，通过esb，对账key为
        String esbSequenceNumber = null;
        if (!StringUtil.isEmptyOrNull(intelligencecreditRequest.getAdditionInfo())) {
            JSONObject jsonObject = JSON.parseObject(intelligencecreditRequest.getAdditionInfo());
            if (null != jsonObject) {
                esbSequenceNumber = jsonObject.getString(ShareParamConstant.ESB_SEQUENCE_NUMBER);
            }
        }
        if (!StringUtil.isEmptyOrNull(esbSequenceNumber)) {
            return esbSequenceNumber;
        } else {
            rglog.error("无esb流水号，交易失败");
            throw new BizException(SmartRouteRspEnums.TRANS_FAIL.getRespCode(), SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
        }
    }
}
